class Solution {
public:


    void reform(vector<vector<int>>& vv, queue<TreeNode*>& qt, TreeNode* root)
    {
        qt.push(root);


        while (!qt.empty())
        {
            vector<int> v;
            int levelsize = qt.size();


            for (int i = 0; i < levelsize; i++)
            {
                TreeNode* node = qt.front();
                if (node)
                    v.push_back(node->val);


                if (node && node->left)
                    qt.push(node->left);
                if (node && node->right)
                    qt.push(node->right);


                qt.pop();
            }
            vv.push_back(v);
        }
    }


    vector<vector<int>> levelOrder(TreeNode* root) {


        vector<vector<int>> vv;
        queue<TreeNode*> qt;


        if (root == nullptr)
            return vv;


        reform(vv, qt, root);
        return vv;
    }
};
